<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <script type="text/javascript" src="./script/rem.js"></script>
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta content="yes" name="apple-mobile-web-app-capable">
    <meta content="yes" name="apple-touch-fullscreen">
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="./css/font-awesome.css" />
    <link rel="stylesheet" type="text/css" href="./css/style.css" />
    <script type="text/javascript" src="./script/jquery.min.js"></script>
    <script type="text/javascript" src="./script/base.js"></script>
    <script type="text/javascript" src="./script/doT.min.js"></script>
</head>

<body>

    <header class="head" style="padding-top:0.4rem;">
        <div class="head-l" tapmode onclick="closeWin()"><i class="fa fa-angle-left"></i></div>
        <h3>支付</h3>
        <div class="head-r"></div>
    </header>
    <div class="head-d" style="padding-top:0.4rem;"></div>

    <div class="pay-t">
        支付金额
        <span id="money_id">￥888.00</span>
    </div>



    <div class="list-text-l mb20">
        <ul>
            <li onclick="wxPay()">
                <img src="image/pay-wechat.png">
                <p>微信支付</p>
                <i class="fa fa-angle-right"></i>
            </li>
            <!-- <li>
                <img src="image/pay-alipay.png">
                <p>支付宝支付</p>
                <i class="fa fa-angle-right"></i>
            </li> -->
        </ul>
    </div>
    <!-- <div class="list-text-l">
        <ul>
            <li>
                <img src="image/pay-ka.png">
                <p>查看银行账号</p>
                <i class="fa fa-angle-right"></i>
            </li>
        </ul>
    </div> -->

    <!-- <div class="btn-2 mt80" onclick="pay()">立即支付</div> -->
    <!-- <div class="btn-2 mt80" onclick="wxPay()">立即支付</div> -->

</body>
<script type="text/javascript" src="./script/api.js"></script>
<script type="text/javascript" src="./script/index.js"></script>
<script type="text/javascript">
    apiready = function(){
        $('#money_id').text('¥'+api.pageParam.price);
    }
    
    function closeWin() {
        api.closeWin({});
    }

    function wxPay(){
        var token = $api.getStorage('token');
        api.ajax({
            url: webAddress + '/api/pay/vip/wx',
            method: 'get',
            data: {
                values: { 
                    id: api.pageParam.order_id
                },
            },
            headers: {
                Authorization: 'Bearer ' + token,
                Accept: 'application/json',
            },
        },function(ret, err){
            if (ret) {
                var wxPay = api.require('wxPay');
                wxPay.payOrder({
                    apiKey: ret.data.appid,
                    orderId: ret.data.prepayid,
                    mchId: ret.data.partnerid,
                    nonceStr: ret.data.noncestr,
                    timeStamp: ret.data.timestamp,
                    package: ret.data.package,
                    sign: ret.data.sign
                }, function(ret, err) {
                    if (ret.status) {
                        // api.execScript({
                        //     name: 'login',
                        //     frameName: 'user_level',
                        //     script: 'user_info();'
                        // });
                        api.sendEvent({
                          name: 'reload'
                        });
                        api.closeToWin({
                            name: 'user_level'
                        });
                    } else {
                        // alert( JSON.stringify( err ) );
                    }
                });
            } else {
                // alert( JSON.stringify( err ) );
            }
        });
    }

    function Pay(mode){
        
    }


    // function wxPay() {
    //     var wxPay = api.require('wxPay');
    //     wxPay.config({
    //     }, function(ret, err) {
    //         if (ret.status) {
    //            alert('配置商户支付参数成功');
    //             wxPay.pay({
    //                     description: 'iPad mini 16G 白色',
    //                     totalFee: '001',
    //                     tradeNo: '1217752501201407033233368012',
    //                 },function(ret,err){
    //                     //coding...
    //                     if(ret.status) {
    //                         alert("您已支付成功");
    //                     } else {
    //                         if(err.code == '-2'){
    //                             alert("您已取消支付");
    //                         } else {
    //                             alert('回调失败'+err.code+err.msg);
    //                         }   
    //                     }
    //                 });
    //         } else {
    //             console.log(err.code);
    //         }
    //     });
    // }  

</script>

</html>
